/* Copyright 2012 Dustin Mitchell <dmmitche [at] gmail [dot] com>
 *
 * Licensed under the GPLv3.  See included LICENSE.txt for full details.
 */

#ifndef __LIST__
#define __LIST__

#include <sys/types.h>

#include "iterator.h"

/* No data is copied into the linked list.  The provided pointer is simply
 * saved into the list.  It is the user's responsibility to free any resources
 * saved in the list. */

struct list_node;

struct list
{
  struct list_node *head;
  struct list_node *tail;
};

struct list_iter
{
  struct iter base;

  struct list_node *node;
};



int list_create (struct list *list);

void list_destroy (struct list *list);

/* After insertion pos points to the node containing data */
int list_insert (struct list *list, void *data, struct list_iter *pos);

/* After removal pos points to the next node */
int list_remove (struct list *list, struct list_iter *pos);

int list_push_front (struct list *list, void *data);

int list_push_back (struct list *list, void *data);

int list_pop_front (struct list *list);

int list_pop_back (struct list *list);

void * list_front (struct list *list);

void * list_back (struct list *list);

int list_empty (struct list *list);

int list_begin (struct list *list, struct list_iter *iter);

int list_end (struct list *list, struct list_iter *iter);

#endif /* __LIST__ */
